# @staticmethod
# def ntroduction():
#     print(f'男,24岁')
#
#
# #  type创建类
# Person = type("Person", (Exception, BaseException), {
#     "name": "张三",
#     "简介": ntroduction
# })
#
# person = Person()
# print(type(person))
#
# print(Person.__bases__)
# print(Person.__doc__)
# Person.简介()
# class MyType(type):
#     def __new__(cls, *args, **kwargs):
#         print("")
#         return super().__new__(cls, *args, **kwargs)
#
#
#
# class Person(metaclass = MyType):
#     def SayHello(self):
#         print("hello")
#
#
# p = Person()
# p.SayHello()

# class A:
#     pass
#
#
# def get_class(f):
#     def convert():
#         print(f.__name__)
#         MYCLASS = type(f.__name__.replace("_", "").title(), (A,), {"__doc__": "我是类"})
#         return MYCLASS
#
#     return convert
#
#
# @get_class
# def my_fun():
#     pass
#
#
# r = my_fun()
# print(r.__name__, r.__bases__, r.__doc__)
# abc = r()
# print(abc, type(abc))


class FileHandler:
    def __init__(self, filename, mode="r"):
        self.filename = filename
        self.mode = mode
        self.file = None

    def __enter__(self):
        print("读取文件")
        self.file = open(self.filename, self.mode, encoding="utf8")
        return self.file

    def __exit__(self, exc_type, exc_val, exc_tb):
        print("关闭文件")
        self.file.close()


fh = FileHandler("06.21装饰器.py")
with FileHandler("06.21装饰器.py") as f:

    print(f.read())
